package client;

import java.net.Socket;

import shared.ChangeCacheInfoMessage;
import shared.ClientCache;
import shared.HeartBitMessage;
import shared.ServerCache;
import shared.ProtocolMessage;

public class Client extends Thread{
	private Socket socket;
	private boolean worked;
	private ClientCache cache;
	private ClientHeartBitSender heartBitSender;
	
	
	public Client(Socket socket) {
		super();
		this.socket = socket;
		this.cache=new ClientCache();
		this.heartBitSender=new ClientHeartBitSender(socket);
		this.heartBitSender.start();
		worked=true;
	}


	@Override
	public void run() {
		while(worked){
			String info=read();
			if (info!=null){
				this.cache.put(info);
			}
		}
	}


	private String read() {
		ProtocolMessage msg=new ProtocolMessage();
		// TODO add reading from socket method< read to 
		if (msg instanceof ChangeCacheInfoMessage){ return ((ChangeCacheInfoMessage) msg).getInformation();}
		return null;
	}
	
	public String get(){
		return cache.get();
	}
	
}
